#include <iostream>
#include <string>
using namespace std;

void last(string &q,int qL,int qR,string &i,int iL,int iR ){
	if( qL < qR ){
		int k = iL;
		for(; k<=iR; k++){
			if( q[qL] == i[k] ) break;
		}
		int Llength = k - iL, Rlength = iR - k;
		last(q,qL+1,qL+Llength,i,iL,k-1);
		last(q,qR-Rlength+1,qR,i,k+1,iR);
		cout << q[qL];
	}else if( qL == qR) cout << q[qL];
}
int main(){
	freopen("in.txt","r",stdin);
	string q,i;
	while( cin>>q>>i ){
		last(q,0,q.length()-1,i,0,i.length()-1); 
		cout << endl;
	}
	return 0;
}
